package controller;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;

import com.dncompute.marrow.Controller;

/**
 * 
 * Access at:
 * http://localhost:8888/basicD
 * http://localhost:8888/basicD/fauna
 * http://localhost:8888/basicD/flora
 * http://localhost:8888/basicD/flora/a
 * 
 * This is a controller which is an evolution of BasicC.
 * 
 * It works much like BasicC, except it takes advantage of 
 * custom method calling based on the endpoint path
 * 
 * @author noelb
 *
 */
public class BasicD extends Controller {
	
	private static final long serialVersionUID = 1L;
	
	
	public void index() throws IOException, ServletException	{
		fauna();
	}
	
	
	public void fauna() throws IOException, ServletException	{
		
		//Create a model object
		ArrayList<String> items = new ArrayList<String>();
		items.add("Anteater");
		items.add("Bear");
		items.add("Camel");
		
		//Place the model in the request
		req.setAttribute("items", items);
		
		//Let the view handle the display of the model
		forward("/view/viewc.jsp");
		
	}
	
	
	public void flora() throws IOException, ServletException	{
		flora(null);
	}
	
	public void flora(String alpha) throws IOException, ServletException	{
		
		//Create a model object
		ArrayList<String> items = new ArrayList<String>();
		
		//Use the parameter to determine which modelset
		if (!alpha.toLowerCase().equals("a")) {
			items.add("Agave");
			items.add("Bergenia");
			items.add("Chrysanthemum");
		} else {
			items.add("Agave");
			items.add("Anemone");
			items.add("Aster");
		}
		
		//Place the model in the request
		req.setAttribute("items", items);
		
		//Let the view handle the display of the model
		forward("/view/viewc.jsp");
		
	}
	

}
